
from django.db import models

# Create your models here.
from django.db import models
from django.utils import timezone
import datetime


# Create your models here.
# 神笔小新的商品节目编排的存档--编辑区
class GoodsComposeSave(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    archivedate = models.CharField(max_length=255, default='', null=True, blank=True)  # 前端显示的存档日期
    member_id = models.BigIntegerField(default=0, null=True)  # 会员id
    member_name = models.BigIntegerField(default=0, null=True)  # 会员姓名，后台自动查询出
    content = models.JSONField(default=dict)  # 具体的内容，以json表示

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now_add=True)  # 同名则覆盖原有存档

    class Meta:
        ordering = ('id',)


# 神笔小新的直播区存档
class LiveBroadcastSave(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    archivedate = models.CharField(max_length=255, default='', null=True, blank=True)  # 前端显示的存档日期
    member_id = models.BigIntegerField(default=0, null=True)  # 会员id
    member_name = models.BigIntegerField(default=0, null=True)  # 会员姓名，后台自动查询出
    content = models.JSONField(default=dict)  # 具体的内容，以json表示

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now_add=True)  # 同名则覆盖原有存档

    class Meta:
        ordering = ('id',)


# 素材
class Material(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    cover_url = models.CharField(max_length=255, default='', null=True, blank=True)
    file_url = models.CharField(max_length=255, default='', null=True, blank=True)
    material_type = models.CharField(max_length=50, default='',)  # 资源类型，用于前台显示的分类，sticker贴纸 background背景 gifspecial特效
    material_subtype = models.CharField(max_length=50, default='', )  # 资源类型的二级分类
    category = models.CharField(max_length=50, default='',)   # 用于前台内部逻辑的分类,，0人物 1图片 2视频 3模型 5声音
    kind = models.CharField(max_length=50, default='',)  # 系统还是本地，sys、local
    image_width = models.BigIntegerField(default=0, null=True)  # 图片原始宽度，上传的时候可以在页面拿到
    image_height = models.BigIntegerField(default=0, null=True)  # 图片原始高度
    video_duration = models.BigIntegerField(default=0, null=True)  # 视频的时长
    member_id = models.BigIntegerField(default=0, null=True) # 会员的id, 当kind为local时,member_id要赋值
    status = models.BooleanField(default=False)  # 状态(1激活，0禁用)
    tags = models.CharField(max_length=255, default='', null=True, blank=True)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)


# tts生成的声音记录
class RecordTts(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    cover_url = models.CharField(max_length=255, default='', null=True, blank=True)
    file_url = models.CharField(max_length=255, default='', null=True, blank=True)
    material_type = models.CharField(max_length=50, default='',)  # 资源类型，用于前台显示的分类，sticker贴纸 background背景 gifspecial特效
    material_subtype = models.CharField(max_length=50, default='', )  # 资源类型的二级分类
    category = models.CharField(max_length=50, default='',)   # 用于前台内部逻辑的分类,，0人物 1图片 2视频 3模型 5声音
    kind = models.CharField(max_length=50, default='',)  # 系统还是本地，sys、local
    image_width = models.BigIntegerField(default=0, null=True)  # 图片原始宽度，上传的时候可以在页面拿到
    image_height = models.BigIntegerField(default=0, null=True)  # 图片原始高度
    video_duration = models.BigIntegerField(default=0, null=True)  # 视频的时长
    member_id = models.BigIntegerField(default=0, null=True) # 会员的id, 当kind为local时,member_id要赋值
    voicetone_type = models.CharField(max_length=255, default='', null=True, blank=True)   # 什么类型的音色 baidu_tts,edge_tts
    voicetone_value = models.CharField(max_length=255, default='', null=True, blank=True)  # 音色的id, 为baidu的index值时，转换为字符串的index
    status = models.BooleanField(default=False)  # 状态(1激活，0禁用)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('-id',)


# AI生成的视频记录
class RecordVideo(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    cover_url = models.CharField(max_length=255, default='', null=True, blank=True)
    file_url = models.CharField(max_length=255, default='', null=True, blank=True)
    material_type = models.CharField(max_length=50, default='',)  # 资源类型，用于前台显示的分类，sticker贴纸 background背景 gifspecial特效
    material_subtype = models.CharField(max_length=50, default='', )  # 资源类型的二级分类
    category = models.CharField(max_length=50, default='',)   # 用于前台内部逻辑的分类,，0人物 1图片 2视频 3模型 5声音
    kind = models.CharField(max_length=50, default='',)  # 系统还是本地，sys、local
    image_width = models.BigIntegerField(default=0, null=True)  # 图片原始宽度，上传的时候可以在页面拿到
    image_height = models.BigIntegerField(default=0, null=True)  # 图片原始高度
    video_duration = models.BigIntegerField(default=0, null=True)  # 视频的时长
    member_id = models.BigIntegerField(default=0, null=True) # 会员的id, 当kind为local时,member_id要赋值
    task_id = models.CharField(max_length=255, default='', null=True, blank=True)
    status = models.BooleanField(default=False)  # 状态(1激活，0禁用)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('-id',)


# 素材子分类
class MaterialSubType(models.Model):
    id = models.BigAutoField(primary_key=True)
    kind = models.CharField(max_length=50, default='', null=True)
    material_type = models.CharField(max_length=50, default='', null=True)  # 资源类型，用于前台显示的分类，sticker贴纸 background背景 gifspecial特效
    category = models.CharField(max_length=50, default='', null=True)
    material_subtype = models.CharField(max_length=50, default='', null=True)  # 资源类型的二级分类
    # order = models.BigIntegerField(null=True, default=0)  # 资源类型的二级分类排序，可以重复，这子分类这个层级不要重复
    name_zh = models.CharField(max_length=50, default='', null=True)  # 资源类型的二级分类显示名称

    class Meta:
        ordering = ('material_type', 'material_subtype',)


class Pose(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    desc = models.CharField(max_length=255, default='', null=True, blank=True)
    posetype = models.CharField(max_length=50, default='vhuman', null=True, blank=True)  # vhuman
    human_id = models.BigIntegerField(null=True)  # 一个虚拟人有多个自己的动作，不同的虚拟人的动作各不相同

    cover_url = models.CharField(max_length=255, default='', null=True, blank=True)
    file_url = models.CharField(max_length=255, default='', null=True, blank=True)

    status = models.BooleanField(null=True)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)


class Animate(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    code = models.CharField(max_length=50, default='', null=True, blank=True)  # 编号，(member,vip,svip)
    cover_url = models.CharField(max_length=255, default='', null=True, blank=True)
    status = models.BooleanField(null=True)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)


class Requirement(models.Model):
    id = models.BigAutoField(primary_key=True)
    desc = models.CharField(max_length=1024, default='', null=True, blank=True)
    client_type = models.CharField(max_length=255, default='', null=True, blank=True)
    company_name = models.CharField(max_length=255, default='', null=True, blank=True)
    contact_name = models.CharField(max_length=255, default='', null=True, blank=True)
    contact_mobile = models.CharField(max_length=255, default='', null=True, blank=True)
    contact_email = models.CharField(max_length=255, default='', null=True, blank=True)
    status = models.IntegerField(default=1)  # 状态(0 草稿 1 提交，2 已看，3 采纳，4 拒绝)
    answer_content = models.CharField(max_length=255, default='', null=True, blank=True)
    answer_name = models.CharField(max_length=255, default='', null=True, blank=True)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('-id',)


# 升级会员的产品包 (升级到神笔会员、升级到VIP、升级到超级VIP、神笔会员升级到超级VIP、VIP升级到超级VIP)
class Package(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    desc = models.CharField(max_length=255, default='', null=True, blank=True)
    benefit = models.CharField(max_length=255, default='', null=True, blank=True)  # 对包产品的受益描述

    from_level_code = models.CharField(max_length=10, default='', null=True, blank=True)
    to_level_code = models.CharField(max_length=10, default='', null=True, blank=True)

    status = models.BooleanField(null=False, default=True)
    price = models.DecimalField(default=0.1, decimal_places=2, max_digits=20, null=True)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('id',)


# 后台用户
class BackUser(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    nickname = models.CharField(max_length=255, default='', null=True, blank=True)

    phone = models.CharField(max_length=50, default='', null=True, blank=True)
    qq_openid = models.CharField(max_length=255, default='', null=True, blank=True)
    wechat_openid = models.CharField(max_length=255, default='', null=True, blank=True)
    passwd = models.CharField(max_length=50, default='', null=True, blank=True)
    login_allowed = models.BooleanField(default=True)
    avatar_url = models.CharField(max_length=1024, default='', null=True, blank=True)
    role_id = models.BigIntegerField(default=0, null=True)

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('-id',)


# 后台用户的角色
class BackRole(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=32)

    class Meta:
        ordering = ('id',)


# 会员
class Member(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    nickname = models.CharField(max_length=255, default='', null=True, blank=True)
    sex = models.CharField(max_length=50, default='', null=True, blank=True)
    province = models.CharField(max_length=50, default='', null=True, blank=True)
    city = models.CharField(max_length=50, default='', null=True, blank=True)
    address = models.CharField(max_length=50, default='', null=True, blank=True)
    postcode = models.CharField(max_length=50, default='', null=True, blank=True)

    phone = models.CharField(max_length=50, default='', null=True, blank=True)
    qq_openid = models.CharField(max_length=255, default='', null=True, blank=True)
    wechat_openid = models.CharField(max_length=255, default='', null=True, blank=True)
    passwd = models.CharField(max_length=50, default='', null=True, blank=True)
    login_allowed = models.BooleanField(default=True)
    avatar_url = models.CharField(max_length=1024, default='', null=True, blank=True)
    level_code = models.CharField(max_length=10, default='', null=True, blank=True)  # 会员级别的编号，不受名称显示的影响，01,普通会员，02 VIP， 03 超级VIP

    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('-id',)


# 会员级别
class MemberLevel(models.Model):
    id = models.BigAutoField(primary_key=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)  # 神笔会员、VIP、超级VIP

    code = models.CharField(max_length=10, default='', null=True, blank=True)  # 编号，(member,vip,svip)
    desc = models.CharField(max_length=255, default='', null=True, blank=True)
    benefit = models.CharField(max_length=255, default='', null=True, blank=True)  # 对会员每种级别的使用范围进行描述
    order = models.BigIntegerField(null=True, default=0)
    status = models.BooleanField(null=False, default=True)
    #
    # create_time = models.DateTimeField(default=timezone.now)
    # modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('id',)


# 会员级别所包含的资源列表
class MemberLevel2Material(models.Model):
    id = models.BigAutoField(primary_key=True)
    level_code = models.CharField(max_length=10, default='', null=True, blank=True)
    material_id = models.BigIntegerField(null=True)


class UploadRecord(models.Model):
    id = models.BigAutoField(primary_key=True)
    urlpath = models.CharField(max_length=255, default='', null=True, blank=True)
    status = models.BooleanField(null=False, default=True)
    create_time = models.DateTimeField(default=timezone.now)

    class Meta:
        ordering = ('id',)


class UserToken(models.Model):
    id = models.BigAutoField(primary_key=True)
    token = models.CharField(max_length=255, default='', null=True, blank=True)

    usertype = models.CharField(max_length=50, default='', null=True, blank=True)
    member_id = models.BigIntegerField(null=True)
    backuser_id = models.BigIntegerField(null=True)
    create_time = models.DateTimeField(default=timezone.now)

    class Meta:
        ordering = ('-id',)


class Gallery(models.Model):
    id = models.BigAutoField(primary_key=True)

    name = models.CharField(max_length=255, default='', null=True, blank=True)
    title = models.CharField(max_length=255, default='', null=True, blank=True)
    description = models.CharField(max_length=255, default='', null=True, blank=True)
    category = models.CharField(max_length=255, default='', null=True, blank=True)
    cover_url = models.CharField(max_length=255, default='', null=True, blank=True)
    video_url = models.CharField(max_length=255, default='', null=True, blank=True)
    model_url = models.CharField(max_length=255, default='', null=True, blank=True)
    view_times = models.BigIntegerField(null=True)
    follow_times = models.BigIntegerField(null=True)
    like_times = models.BigIntegerField(null=True)
    target = models.CharField(max_length=255, default='', null=True, blank=True)
    status = models.BigIntegerField(null=True)
    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('-id',)


# 语音音色
class VoiceTone(models.Model):
    id = models.BigAutoField(primary_key=True)
    tts_category = models.CharField(max_length=50, default='', null=True, blank=True)
    name = models.CharField(max_length=255, default='', null=True, blank=True)
    name_zh = models.CharField(max_length=255, default='', null=True, blank=True)
    sex = models.CharField(max_length=50, default='', null=True, blank=True)
    avatar_url = models.CharField(max_length=1024, default='', null=True, blank=True)
    audition_url = models.CharField(max_length=1024, default='', null=True, blank=True) # 试听url
    baidu_index = models.BigIntegerField(null=True)
    recommend_flag = models.BooleanField(null=True)
    hot_flag = models.BooleanField(null=True)
    status = models.BooleanField(null=True)
    create_time = models.DateTimeField(default=timezone.now)
    modify_time = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ('sex', '-id',)
